/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "pch.h"
#include "表达式代码解析.h"

static std::map<std::u16string, E_运算符> g括号运算符映射 = {
    {"{", E_运算符::e_圆括号}
};



void f_分解表达式(std::vector<std::u16string_view>::iterator& it
                , std::vector<std::u16string_view>::iterator& end
                , 
                ){
    
    auto begin = it;
    {
        std::vector<std::u16string_view> 前;
        while(it != end){
            if (*it == "(") {
                auot 中 = f_括号域(it, end, "(", ")");
                if(f_model_函数是否存在(, 前.back())){
                    前.pop();
                }
            }
            else if(*it == "[") {
                auot 中 = f_括号域(it, end, "[", "]");
                if(f_model_变量是否存在(, 前.back())){
                    前.pop();
                }
            }
            else if(*it == "{") {
                auot 中 = f_括号域(it, end, "{", "}");
            }
            else {
                前.push_back(*it);
                ++it;
            }
        }
        
        auto 代码块 = f_代码切片(it, end, "(");
        auto 前表达式 = f_分解表达式(begin, it);
        
        if(代码块.size()){
            auot 中 = f_代码切片(it, end, ")");
            if(中.size()){
                auto it_s = 代码块.begin();
                auto end_s = 代码块.end();
                f_分解表达式(it_s, end_s);
            }

            auto 后 = f_分解表达式(it, end);
            if(后.size()){
                f_分解表达式(it_s, end_s);
            }
        }
    }

    {
        auto 代码块 = f_代码切片(it, end, "{");
        auto 前 = f_分解表达式(begin, it);
        
        if(代码块.size()){
            auot 中 = f_代码切片(it, end, "}");
            if(中.size()){
                auto it_s = 代码块.begin();
                auto end_s = 代码块.end();
                f_分解表达式(it_s, end_s);
            }

            auto 后 = f_分解表达式(it, end);
            if(后.size()){
                f_分解表达式(it_s, end_s);
            }
        }
        
        //括号分解
        const std::u16string 括号左[] = {"{", "(", "["};
        const std::u16string 括号右[] = {"}", ")", "]"};

        bool 返回 = false;
        for(uint32 i=0; i<3; ++i) {
            auto 代码块 = f_代码切片(it, end, 括号左[i];
            auto 前 = f_分解表达式(begin, it);
            
            if(代码块.size()){
                auot 中 = f_代码切片(it, end, 括号右[i]);
                if(中.size()){
                    auto it_s = 代码块.begin();
                    auto end_s = 代码块.end();
                    f_分解表达式(it_s, end_s);
                }

                auto 后 = f_分解表达式(it, end);
                if(后.size()){
                    f_分解表达式(it_s, end_s);
                }
            }
        }
        
    }
    
    
    {
        auto 代码块 = f_代码切片(it, end, "[");
        if(代码块.size()){
            auot 内部代码块 = f_代码切片(it, end, "]");
        }
    }

    {
        auto 代码块 = f_代码切片(it, end, "{");
        if(代码块.size()){
            auot 内部代码块 = f_代码切片(it, end, "}");
        }
    }


    for(; it != end; ){
        //0
        if(*it == "("){
            auto 代码块 = f_代码切片(it, end, "(");
            auto it_s = 代码块.begin();
            auto end_s = 代码块.end();
            f_分解表达式(it_s, end_s);
        }

        if(*it == "["){
            auto 代码块 = f_代码切片(it, end, "[");
            auto it_s = 代码块.begin();
            auto end_s = 代码块.end();
            f_分解表达式(it_s, end_s);
        }

        if(*it == "."){
            
        }

        if(*it == "{"){
            
        }

        //1
        if(*it == "++"){
            
        }
        if(*it == "--"){
            
        }
        if(*it == "!"){
            
        }
        if(*it == "~"){
            
        }
        if(*it == "*"){
            
        }
        if(*it == "&"){
            
        }
        if(*it == "sizeof"){
            
        }
        if(*it == "new"){
            
        }
        if(*it == "delete"){
            
        }

    //2


    }
}

void f_变量初始化表达式解析(std::vector<std::u16string_view>::iterator& it
                , std::vector<std::u16string_view>::iterator& end
                , S_变量代码块& 变量代码
                ) {
    auto it = 变量代码.初始表达式.begin();
    auto end = 变量代码.初始表达式.end();

    for(; it != end; ){
        
        if(it != end){
            if(*it == "="){

            }
            
            
        } else {
            break;
        }
        ++it;
    }
}



